<template>
	<view class="container">
		<!-- 搜索框 -->
		<view class="search-section">
			<view class="search-input u-f-ajc">
				<u-search bg-color="#f4f4f4" shape="square" placeholder="请输入您喜欢的商品" @search="search" :show-action="false" :clearabled="true" v-model="keyword"></u-search>
			</view>
		</view>
		<view class="index-elements" v-for="component in components_list" :key="component.id">
			<!-- 轮播图 -->
			<view class="swiper-section" v-if="component.type == 'banner'">
				<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" indicator-active-color="#fff">
					<swiper-item v-for="item in component.data" :key="item.id" @click="$jump(item.linkUrl)">
						<view class="swiper-item"><image :src="item.imgUrl" mode=""></image></view>
					</swiper-item>
				</swiper>
			</view>

			<uni-carousel
				v-if="component.type == 'nav'"
				:carouselList="Object.values(component.data)"
				height="90"
				:type="component.style.type"
				:num="component.style.num"
				@onCarousel="onCarousel"
			></uni-carousel>

			<!-- 头条 -->
			<view class="notice-section" v-if="component.type == 'title'">
				<view class="notice u-f-ac">
					<image src="/static/img/index_notice.png" mode=""></image>
					<view class="line"></view>
					<view class="content">{{ component.data }}</view>
				</view>
			</view>

			<!-- 海报图片-->
			<view class="pic-group" v-if="component.type == 'adimg'">
				<view :class="[`pic-style pic-style-${component.style.type}`]">
					<image
						v-if="component.style.type == 1 || component.style.type == 5 || component.style.type == 7"
						v-for="(item, id, index) in component.data"
						:key="index"
						class="img-pic"
						:src="item.imgUrl"
						@click="$jump(item.linkUrl)"
						mode="widthFix"
					></image>
					<image v-else v-for="(item, id, index) in component.data" :key="item.id" class="img-pic" :src="item.imgUrl" @click="$jump(item.linkUrl)"></image>
				</view>
			</view>
			<!-- 商品列表 -->
			<view class="goods-section" v-if="component.type == 'goods_list'">
				<view class="goods-header">{{ component.style.title }}</view>
				<view class="goods-list u-f-jsb u-f-fw">
					<view class="goods-item" v-for="(item, index) in component.data" :key="index" @click="$jump(item.url)">
						<image :src="item.logo" mode=""></image>
						<view class="title u-line-clamp">{{ item.title }}</view>
						<view class="price u-f-ac">
							<view style="font-size: 28upx;">￥</view>
							{{ item.price_market }}
							<text>￥{{ item.price_cost }}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 150upx;background-color: #f3f3f3;"></view>

		<!-- #ifndef APP-PLUS -->
		<tabbar :current-page="0"></tabbar>
		<!-- #endif -->
	</view>
</template>

<script>
import service from '@/store/service.js';
import uicons from '@/components/uni-icons/uni-icons.vue';
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

export default {
	components: {
		uicons,
		uniLoadMore
	},
	data() {
		return {
			keyword: '',
			components_list: [],
			goodList: []
		};
	},
	onLoad: function(e) {
		this.showPage();
	},
	methods: {
		search(value) {
			console.log(value);
			uni.navigateTo({
				url: '../shoppingCart/searchList?keyword=' + value
			});
		},
		showPage: function() {
			let self = this;
			this.$http.get(service.api.main.getpage).then(function(res) {
				if (res.code == 1) {
					self.components_list = res.data;
				}
			});
		},

		onCarousel: function(item) {
			var url = item.linkUrl;
			if (url == '') {
				uni.showToast({
					icon: 'none',
					title: '该功能暂未开放'
				});
			} else {
				uni.navigateTo({
					url: url
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	background-color: $uni-bg-color;

	.search-section {
		width: 100vw;
		padding: 30rpx;

		.search-input {
			width: 690rpx;
			height: 66rpx;
			background-color: #f1f1f1;
			border-radius: 33rpx;

			text {
				margin-left: 10rpx;
				color: $uni-text-color-grey;
			}
		}
	}

	.index-elements {
		.swiper-section {
			width: 100vw;
			height: 100%;
			padding: 20rpx;

			.swiper {
				height: 100%;
			}

			.swiper-item {
				width: 710rpx;
				height: 100%;

				image {
					width: 100%;
					height: 100%;
					border-radius: 10upx;
				}
			}
		}

		.menu-section {
			display: flex;
			flex-wrap: wrap;
			align-items: center;

			//display: flex;
			.menu-item {
				width: 25%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				margin-top: 20upx;
				margin-bottom: 20upx;
				font-size: 20upx;

				image {
					width: 80rpx;
					height: 80rpx;
					padding-bottom: 20upx;
				}
			}
		}
	}

	.notice-section {
		padding: 20rpx;

		.notice {
			width: 710rpx;
			height: 72rpx;
			border-radius: 33rpx;
			display: flex;
			background-color: #f4f4f4;
			line-height: 72rpx;

			image {
				width: 121rpx;
				height: 32rpx;
				margin: 20upx 0;
				padding-left: 20rpx;
			}

			.line {
				width: 2rpx;
				height: 32rpx;
				background-color: #c3c3c3;
				margin: 20rpx 15rpx;
			}

			.content {
				color: $uni-text-color;
				font-weight: bold;
			}
		}
	}

	.group-section {
		padding: 20rpx;
		border-bottom: 20rpx solid #f3f3f3;
		box-sizing: border-box;
		width: 100%;

		.group-header {
			.title {
				font-size: 32rpx;
				font-weight: bold;
				color: #000;
			}

			.sub-title {
				font-size: 22rpx;
				color: #999;
				margin-left: 20rpx;
			}

			image {
				width: 94rpx;
				height: 26rpx;
			}
		}

		.group-content {
			display: flex;
			overflow: hidden;

			.group-item {
				// width: 225rpx;
				width: 32%;
				margin: 15rpx;

				image {
					width: 224rpx;
					height: 224rpx;
					margin: 20rpx 0 10rpx;
				}

				.content {
					box-sizing: border-box;
					width: 224rpx;
					height: 47rpx;
					display: flex;
					justify-content: space-around;
					background: linear-gradient(90deg, #ffcc99, #e4842e);
					border-radius: 0px 0px 18upx 18upx;

					.label {
						padding: 0 10upx;
						// width: 128rpx;
						height: 42rpx;
						font-size: 20rpx;
						line-height: 42rpx;
						text-align: center;
						// display: flex;
						// justify-content: center;
						// align-items: center;
						transform: scale(0.9);
						background: #f69739;
						border-radius: 18upx;
					}

					.price,
					.label {
						color: #ffffff;
					}

					.price {
						font-size: 24upx;
						font-weight: bold;
					}
				}

				.name {
					width: 224rpx;
					margin-top: 10rpx;
					// text-align: center;
				}
			}

			& :nth-child(1),
			& :nth-child(3) {
				margin-left: 0;
				margin-right: 0;
			}
		}
	}

	.goods-section {
		background-color: #f3f3f3;
		padding: 0 20rpx 0;

		.goods-header {
			color: #262626;
			font-size: 34rpx;
			font-weight: bold;
			margin-bottom: 20rpx;
		}

		.goods-list {
			// margin-bottom: 50rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.goods-item {
				border-radius: 20upx;
				width: 345rpx;
				background-color: #ffffff;
				margin-bottom: 20rpx;

				image {
					width: 100%;
					height: 330rpx;
					margin-bottom: 20rpx;
					border-radius: 20upx 20upx 0 0;
				}

				.title {
					padding: 10rpx 30rpx 0;
					font-size: 26rpx;
					color: $uni-text-color;
					font-weight: bold;
					line-height: 1.4;
				}

				.price {
					padding: 14rpx 24rpx;
					font-size: 36rpx;
					font-weight: bold;
					color: #f81149;

					text {
						font-weight: 100;
						font-size: 20rpx;
						color: #999;
						text-decoration: line-through;
						margin-left: 15rpx;
					}
				}
			}
		}
	}
}

.pic-group {
	padding: 20upx;
}

.img-pic {
	display: none;
}

.pic-style {
	display: flex;
	justify-content: space-around;
	position: relative;
	z-index: 1;
	margin: 0 auto;
	width: 100%;

	image {
		width: 100%;
		z-index: -1;
		zoom: 1;
	}
}

.pic-style-1 {
	flex-direction: column;
	align-items: center;

	image {
		display: block;
		width: 100%;
	}
}

.pic-style-2 {
	image {
		&:nth-child(1) {
			display: block;
			width: 40%;
			height: 365upx;
		}

		&:nth-child(2) {
			display: block;
			width: 60%;
			height: 365upx;
		}
	}
}

.pic-style-3 {
	height: 365upx;
	image {
		&:nth-child(1) {
			display: block;
			width: 40%;
			height: 365upx;
			position: absolute;
			left: 0;
		}
		&:nth-child(2) {
			display: block;
			width: 60%;
			height: 180upx;
			position: absolute;
			right: 0;
		}
		&:nth-child(3) {
			display: block;
			width: 60%;
			height: 180upx;
			position: absolute;
			// right: 222upx;
			right: 0;
			bottom: 0;
		}
		// &:nth-child(4) {
		// 	display: block;
		// 	width: 216upx;
		// 	height: 180upx;
		// 	position: absolute;
		// 	right: 0;
		// 	bottom: 0;
		// }
	}
}

.pic-style-4 {
	height: 365upx;
	image {
		&:nth-child(1) {
			display: block;
			width: 40%;
			height: 365upx;
			position: absolute;
			left: 0;
		}

		&:nth-child(2) {
			display: block;
			width: 60%;
			height: 180upx;
			position: absolute;
			right: 0;
		}

		&:nth-child(3) {
			display: block;
			width: 216upx;
			height: 180upx;
			position: absolute;
			right: 222upx;
			bottom: 0;
		}

		&:nth-child(4) {
			display: block;
			width: 216upx;
			height: 180upx;
			position: absolute;
			right: 0;
			bottom: 0;
		}
	}
}

.pic-style-5 {
	display: flex;
	justify-content: space-around;

	image {
		flex: 1;
		margin: 0 5upx;

		&:first-child {
			margin: 0;
			display: block;
		}

		&:nth-child(2) {
			margin-right: 0;
			display: block;
		}

		&:nth-child(3) {
			display: block;
		}

		&:nth-child(4) {
			margin: 0;
			display: block;
		}
	}
}

.pic-style-6 {
	display: flex;
	flex-wrap: wrap;

	> image {
		&:nth-child(1) {
			display: block;
			width: 50%;
			height: 200upx;
			margin-top: 5upx;
		}

		&:nth-child(2) {
			display: block;
			width: 50%;
			height: 200upx;
			margin-top: 5upx;
		}

		&:nth-child(3) {
			display: block;
			width: 50%;
			height: 200upx;
			margin-top: 5upx;
		}

		&:nth-child(4) {
			display: block;
			width: 50%;
			height: 200upx;
			margin-top: 5upx;
		}
	}
}

.pic-style-7 {
	display: inline-flex;
	flex-flow: row wrap;
	align-content: flex-start;

	image {
		display: block;
		box-sizing: border-box;
		flex: 0 0 50%;
	}
}

.pic-style-8 {
	image {
		flex: 1;

		&:nth-child(1) {
			display: block;
			height: 250upx;
		}

		&:nth-child(2) {
			display: block;
			height: 250upx;
		}

		&:nth-child(3) {
			display: block;
			height: 250upx;
		}
	}
}

/deep/ .u-content {
	background-color: #f4f4f4 !important;
}
.good-list {
	margin: 20upx 20upx 0;

	.good-item {
		border-radius: 20upx;
		width: 220rpx;
		background-color: #ffffff;
		margin-bottom: 20rpx;

		image {
			width: 100%;
			height: 220rpx;
			margin-bottom: 20rpx;
		}

		.title {
			padding: 10rpx 10rpx 0;
			font-size: 26rpx;
			color: $uni-text-color;
			font-weight: bold;
			line-height: 1.4;
		}

		.price {
			padding: 14rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #f81149;

			text {
				font-weight: 100;
				font-size: 20rpx;
				color: #999;
				margin-left: 15rpx;
			}
		}
	}
}
.pic {
	width: 92%;
	height: 175upx;
	margin-left: 30upx;
	// margin-top: 20upx;
}
</style>
